//
//  LXCarStockImagView.m
//  ZuLinProject
//
//  Created by bancheng on 2022/7/9.
//  Copyright © 2022 LX_App. All rights reserved.
//

#import "LXCarStockImagView.h"
#import "LXBigImageView.h"
@interface LXCarStockImagView()
@property(nonatomic) UIView *imgView;
@property(nonatomic) UIImageView *imgV;
@end
@implementation LXCarStockImagView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if (self) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 100, 20)];
        label.text = @"车型图片";
        label.textColor = ColorWith333333;
        label.font = FONT_SIZE(18);
        [self addSubview:label];
        
        
        self.imgView = [[UIView alloc] initWithFrame:CGRectMake(12, label.Y_height + 10, self.width - 24, self.height - label.Y_height - 10)];
        [self addSubview:self.imgView];
    }
    return self;
}
+(CGFloat)getCellHeightWithDataAry:(NSArray*)dataAry
{
    CGFloat height = dataAry.count/3 *KHeightScale(70);
    if (dataAry.count%3 !=0 ){
        height = (dataAry.count/3 +1) *KHeightScale(70) ;
    }
    CGFloat count = dataAry.count/3.0;
    return height + (8 * ceil(count));
}

- (void)setImageArys:(NSArray *)imageArys{
    _imageArys = imageArys;


    CGFloat margin = 8;
    CGFloat W = (self.imgView.width - 30) / 3;
    CGFloat H = KHeightScale(70);
    for (int i = 0; i < imageArys.count; i++) {
        
        NSInteger row = i/3;
        NSInteger col = i%3;
        
        
        CGFloat X =  col  * (W + margin) + margin;
        CGFloat Y =  row * (H + margin);
        
        UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(X, Y, W, H)];
        [imgV sd_setImageWithURL:[NSURL URLWithString:[NSString isChinese:[HTTP_URL stringByAppendingString:imageArys[i]]]] placeholderImage:Image(@"暂无图片")];
        [imgV addCorner:3];
        self.imgV = imgV;
        [imgV whenTapped:^{
            [self clickBigImageViewAction:i];
        }];
        [self.imgView addSubview:imgV];
        
    }
    
    
    
}

-(void)clickBigImageViewAction:(NSInteger)index{
    

    LXBigImageView *view = [[LXBigImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) WithShowImageAry:self.imageArys];
    [view.scrollView setContentOffset:CGPointMake(ScreenWidth * index, 0)];
    [[UIApplication sharedApplication].delegate.window addSubview:view];
    
    
}



@end
